# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=eigen
pkgbase=mingw-w64-${_realname}3
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}3")
pkgver=3.3.9
pkgrel=1
pkgdesc="Lightweight C++ template library for vector and matrix math (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64')
url='https://eigen.tuxfamily.org/'
license=('MPL2')
options=('strip' 'staticlibs')
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-fftw"
             "${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-mpfr")
source=("https://gitlab.com/libeigen/eigen/-/archive/${pkgver}/eigen-${pkgver}.tar.bz2"
        'eigen-3.1.2_osversion.patch'
        'TryRunResults.cmake'
        'eigen-pkgconfig.patch'
        'install_FindEigen3.patch')
sha256sums=('0fa5cafe78f66d2b501b43016858070d52ba47bd9b1016b0165a7b8e04675677'
            '604b5c33e98a5873a81bb92a734dbf30547b482fde519aed5abc5e9ff2dffc6b'
            '9ebec4761a7de150ade4b421407a4b5148065416fa8010ecfbdd404bab68f899'
            '38d41a475a65de5ad92d1939c9f4fa7460b8152d5beb7256bcbaf630460b5c89'
            'c219f577e51571482fdfb38aec104c806cc6ee4c455627d70e99e59d2df7c32d')

prepare() {
  cd "${srcdir}"/eigen-${pkgver}

  patch -Np2 -i "${srcdir}/eigen-3.1.2_osversion.patch"
  patch -Np1 -i "${srcdir}/eigen-pkgconfig.patch"
  patch -Np1 -i "${srcdir}/install_FindEigen3.patch"
}

build() {
  [[ -d build-${MINGW_CHOST} ]] && rm -rf build-${MINGW_CHOST}
  mkdir -p build-${MINGW_CHOST} && cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DEIGEN_BUILD_PKGCONFIG=ON \
    -DFFTW_USE_STATIC_LIBS=ON \
    -DFFTW_ROOT=${MINGW_PREFIX} \
    ../eigen-${pkgver}

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
}
